﻿using Microsoft.Win32;
using System.Linq;
namespace org.googlecoders.GetLatestChromium.Properties {
    
    
    // This class allows you to handle specific events on the settings class:
    //  The SettingChanging event is raised before a setting's value is changed.
    //  The PropertyChanged event is raised after a setting's value is changed.
    //  The SettingsLoaded event is raised after the setting values are loaded.
    //  The SettingsSaving event is raised before the setting values are saved.
	public sealed partial class Settings
	{
        
        public Settings() {
            this.SettingChanging += this.SettingChangingEventHandler;
            this.SettingsSaving += this.SettingsSavingEventHandler;
        }
        
        private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
            // Add code to handle the SettingChangingEvent event here.
        }
        
        private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
			
			RegistryKey run = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
			if (run != null)
			{
				if (StartWithWindows)
					run.SetValue("GetLatestChromium", '"'+System.Windows.Forms.Application.ExecutablePath+'"', RegistryValueKind.String);
				else
					run.DeleteValue("GetLatestChromium",false);
				run.Close();
			}

            // Add code to handle the SettingsSaving event here.
        }
        
		public BuildLocation Location
		{
			get
			{
				return BuildLocation.GetLocations().SingleOrDefault(l => l.Name == Source);
			}
		}
    }
}
